<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*"%>
<%@page import="support.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Country Of Resident Page</title>
</head>
<body>
	<%
		//read from last page and set attributes to sessions
		String countryOfCitizenship = request
				.getParameter("CountryOfCitizenship");
		session.setAttribute("CountryOfCitizenship", countryOfCitizenship);
	%>
	<p>
		Hello,
		<%=session.getAttribute("FirstName")%>
		<%=session.getAttribute("MiddleI")%>
		<%=session.getAttribute("LastName")%>
	<p>
		Your country of citizenship is:
		<%=countryOfCitizenship%>
	<p>Choose your country of resident:
	<form method="get" action="address.jsp">
		<p>
			<a href="address.jsp?CountryOfResident=<%=countryOfCitizenship%>">Same
				with country of citizenship</a>
			<%
				//read countries from .txt file to vector 
				support s = new support();

				//getCountries returns a vector of the countries to be used for choosing citizenship
				Vector countries = s.getCountries();
			%>
		
		<table border="1">
			<%
				//print all the countries and display in 3 columns
				int i;
				for (i = 0; i < countries.size() / 3; i++) {
			%>
			<tr>
				<td><a
					href="address.jsp?CountryOfResident=<%=countries.get(i * 3)%>">
						<%
							if (i * 3 <= countries.size())
									out.println(countries.get(i * 3) + "<br>");
						%>
				</a></td>
				<td><a
					href="address.jsp?CountryOfResident=<%=countries.get(i * 3 + 1)%>">
						<%
							if (i * 3 + 1 <= countries.size())
									out.println(countries.get(i * 3 + 1) + "<br>");
						%>
				</a></td>
				<td><a
					href="address.jsp?CountryOfResident=<%=countries.get(i * 3 + 2)%>">
						<%
							if (i * 3 + 2 <= countries.size())
									out.println(countries.get(i * 3 + 2) + "<br>");
						%>
				</a></td>
			</tr>
			<%
				}
			%>
			<%
				//print the last row of  countries, if it is less than 3 columns
				if (countries.size() % 3 != 0) {
					for (i = 0; i < countries.size() % 3; i++) {
			%>
			<tr>
				<td><a
					href="address.jsp?CountryOfResident=<%=countries.get(countries.size() - 1 - i)%>">
						<%
							out.println(countries.get(countries.size() - 1 - i));
						%>
				</a></td>
			</tr>
			<%
				}
				}
			%>

		</table>
	</form>
</body>
</html>